package service.impl;

import model.LogEntity;
import model.entity.Order;
import model.enums.OrderStatus;
import service.OrderRepository;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/25 10:00
 */

public class MemoryOrderRepository implements OrderRepository {
    private static final Map<String, Order> orders = new ConcurrentHashMap<>();
    private static final Map<String, LogEntity> logs = new ConcurrentHashMap<>();
    @Override
    public void save(Order order) {
        orders.put(order.getOrderId(), order);
    }

    @Override
    public Order findById(String orderId) {
        return orders.get(orderId);
    }

    @Override
    public void updateStatus(String orderId, OrderStatus status) {
        Order order = orders.get(orderId);
        if(order != null) {
            order.setStatus(status);
        }
    }

    @Override
    public void logModification(String orderId, LogEntity logEntity) {
        logs.put(orderId,logEntity);
    }

    @Override
    public LogEntity getLogByOrderId(String orderId) {
        return logs.get(orderId);
    }
}